package com.mryang.hds.controller;

import com.mryang.hds.entity.TripInfo;
import com.mryang.hds.service.ITripInfoService;
import com.mryang.hds.utils.JWTUtil;
import com.mryang.hds.utils.ResultJson;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * @author Genius
 * @version 1.0.0
 * @ClassName TripInfoController.java
 * @Description TODO 行程信息 控制器
 * @createTime 2023年01月07日 22:57:00
 */


@RequestMapping("/api/trip")
@RestController
public class TripInfoController {

    @Resource
    private ITripInfoService iTripInfoService;

    /**
     * 添加行程信息
     * @param steps 行程信息
     * @return 执行结果
     */
    @PostMapping("/addTrip")
    public ResultJson insertTripInfo(@RequestBody List<TripInfo> steps, HttpServletRequest httpServletRequest){

        // System.out.println(steps.toString());
        // 获取登录用户编号
        String token = httpServletRequest.getHeader("token");
        Integer uId = JWTUtil.getTokenInfoIndex(token);

        iTripInfoService.insertTripInfo(steps,uId);

        return ResultJson.success("行程信息添加成功");

    }
}
